/**
 * 下拉翻页插件
 */

export default {
  data() {
    return {
      pageNum: 1, //页数
      pageSize: 10, //行数
      alllist: undefined,
      gettool: true, //连接开关
      scrollTopNum: null, //当前滚动值
      nodata: false, //无数据开关
      innerHeightNum: null,
      outerHeightNum: null,
      bottomtcp: false
    };
  },
  watch: {
    scrollTopNum: function(nv, ov) {
      if (nv > ov) {
        this.getlisttobottom();
      } else {
        return;
      }
    }
  },
  mounted() {
    document.addEventListener("scroll", this.scrollMoreData, false);
  },
  destroyed() {
    document.removeEventListener("scroll", this.scrollMoreData, false);
  },
  methods: {
    scrollMoreData() {
      let innerHeight = document.querySelector("#sslist").clientHeight;
      let outerHeight = document.documentElement.clientHeight;
      let scrollTop =
        document.documentElement.scrollTop ||
        document.body.scrollTop ||
        window.pageYOffset;
      this.innerHeightNum = innerHeight;
      this.outerHeightNum = outerHeight;
      this.scrollTopNum = scrollTop;
    },
    getlisttobottom() {
      let _vm = this;
      if (_vm.bottomtcp == false) {
        if (
          this.outerHeightNum + this.scrollTopNum + 0.5 >
          this.innerHeightNum
        ) {
          _vm.bottomtcp = true;
          _vm.getlistall();
        }
      } else {
        return;
      }
    }

    //写获取数据方法时 需要写判断传入是否有数据 无数据nodata = true  分页关联data中得pageSize
  }
};
